package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.SysTradeset;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysWater;
import com.ruoyi.system.service.ISysWaterService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2025-01-07
 */
@Controller
@RequestMapping("/system/water")
public class SysWaterController extends BaseController
{
    private String prefix = "system/water";

    @Autowired
    private ISysWaterService sysWaterService;

    @RequiresPermissions("system:water:view")
    @GetMapping()
    public String water(ModelMap mmap)
    {
        SysWater sysWater = sysWaterService.selectSysWaterList(new SysWater()).get(0);
        mmap.put("sysWater", sysWater);
        return prefix + "/water";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:water:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysWater sysWater)
    {
        startPage();
        List<SysWater> list = sysWaterService.selectSysWaterList(sysWater);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:water:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysWater sysWater)
    {
        List<SysWater> list = sysWaterService.selectSysWaterList(sysWater);
        ExcelUtil<SysWater> util = new ExcelUtil<SysWater>(SysWater.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:water:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysWater sysWater)
    {
        return toAjax(sysWaterService.insertSysWater(sysWater));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:water:edit")
    @GetMapping("/edit/{text}")
    public String edit(@PathVariable("text") String text, ModelMap mmap)
    {
        SysWater sysWater = sysWaterService.selectSysWaterByText(text);
        mmap.put("sysWater", sysWater);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:water:view")
    @Log(title = "修改水印设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysWater sysWater)
    {
        String watermark = "<defs><pattern id='ds_watermark' x='0' y='0' width='"+sysWater.getWidth()+"' height='"+sysWater.getHeight()+"'" +
                " patternUnits='userSpaceOnUse'><text x='"+sysWater.getX()+"' y='"+sysWater.getY()+"' font-size='"+sysWater.getSize()+"'" +
                " font-family='"+sysWater.getFont()+"' transform='rotate("+sysWater.getRotate()+")' fill='rgba("+sysWater.getFill()+")'>"+sysWater.getText()+"" +
                "</text></pattern></defs><rect width='100%' height='100%' fill='url(#ds_watermark)' />";
        sysWater.setWatermark(watermark);
        return toAjax(sysWaterService.updateSysWater(sysWater));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:water:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysWaterService.deleteSysWaterByTexts(ids));
    }
}
